﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

/*
exitScriptKey		= q & s
exitEmulatorKey		= Esc
toggleCursorKey		= t
pauseVPinball		= p
hideCursor		= true
hideDesktop		= true
hideTaskbar		= true
useExitScreen		= true
usePauseKey		= true
useLoadScreen		= true
fadespeed		= 25
useExitAsPause		= true
exitEmulatorKey2	= 1
exitEmulatorKey3	= Enter
pauseFPKey		= RButton
saveFPTables		= true
*/

namespace HyperPin_Database_Editor
{
    public partial class HPFPLaunchSettings : HPSettingsPanel
    {
        static string iniExitScriptKey = "exitScriptKey";
        static string iniExitEmulatorKey = "exitEmulatorKey";
        static string iniPauseVPKey = "pauseKey";
        static string iniHideCursor = "hideCursor";
        static string iniHideDesktop = "hideDesktop";
        static string iniHideTaskbar = "hideTaskbar";
        static string iniUseExitScreen = "useExitScreen";
        static string iniUsePauseKey = "usePauseKey";
        static string iniUseLoadScreen = "useLoadScreen";
        static string iniFadeSpeed = "fadespeed";
        static string iniUseExitAsPause = "useExitAsPause";
        static string iniExitEmulatorKey2 = "exitEmulatorKey2";
        static string iniExitEmulatorKey3 = "exitEmulatorKey3";
        static string iniPauseFPKey = "pauseFPKey";
        static string iniSaveFPTables = "saveFPTables";
        static string iniToggleCursorKey = "toggleCursorKey";

        public HPFPLaunchSettings()
        {
            InitializeComponent();

            comboPauseVPKey.Items.AddRange(HPKeyboardSettings.keyNames());
            comboPauseVPKey.Items.AddRange(HPKeyboardSettings.buttonNames());

            comboPauseFPKey.Items.AddRange(HPKeyboardSettings.keyNames());
            comboPauseFPKey.Items.AddRange(HPKeyboardSettings.buttonNames());

            comboToggleCursorKey.Items.AddRange(HPKeyboardSettings.keyNames());
            comboToggleCursorKey.Items.AddRange(HPKeyboardSettings.buttonNames());

            comboExitEmulatorKey.Items.AddRange(HPKeyboardSettings.keyNames());
            comboExitEmulatorKey.Items.AddRange(HPKeyboardSettings.buttonNames());

            comboExitEmulatorKey2.Items.AddRange(HPKeyboardSettings.keyNames());
            comboExitEmulatorKey2.Items.AddRange(HPKeyboardSettings.buttonNames());

            comboExitEmulatorKey3.Items.AddRange(HPKeyboardSettings.keyNames());
            comboExitEmulatorKey3.Items.AddRange(HPKeyboardSettings.buttonNames());
        }

        public override void doLoadSettings()
        {
            checkUseLoadScreen.Checked = readSettingBool(iniUseLoadScreen, true);
            checkUsePauseKey.Checked = readSettingBool(iniUsePauseKey, true);
            checkUseExitAsPause.Checked = readSettingBool(iniUseExitAsPause, true);
            comboPauseVPKey.Text = readSetting(iniPauseVPKey, "p");
            comboPauseFPKey.Text = readSetting(iniPauseFPKey, "RButton");
            checkUseExitScreen.Checked = readSettingBool(iniUseExitScreen, true);
            comboExitEmulatorKey.Text = readSetting(iniExitEmulatorKey, "Esc");
            comboExitEmulatorKey2.Text = readSetting(iniExitEmulatorKey2, "1");
            comboExitEmulatorKey3.Text = readSetting(iniExitEmulatorKey3, "Enter");
            checkHideCursor.Checked = readSettingBool(iniHideCursor, true);
            checkHideDesktop.Checked = readSettingBool(iniHideDesktop, true);
            checkHideTaskbar.Checked = readSettingBool(iniHideTaskbar, true);
            comboToggleCursorKey.Text = readSetting(iniToggleCursorKey, "t");
            checkSaveFPTables.Checked = readSettingBool(iniSaveFPTables, true);
            textExitScriptKey.Text = readSetting(iniExitScriptKey, "q & s");
            numericFadeSpeed.Value = readSettingInt(iniFadeSpeed, 25);

            //numericBottomX.Value = readSettingInt(iniBottomX, 300);
            //numericCenterY.Value = readSettingInt(iniCenterY, 360);
            updateOptionalControls();
        }

        public override void doSaveSettings()
        {
            writeSettingBool(iniUseLoadScreen, checkUseLoadScreen.Checked);
            writeSettingBool(iniUsePauseKey, checkUsePauseKey.Checked);
            writeSettingBool(iniUseExitAsPause, checkUseExitAsPause.Checked);
            writeSetting(iniPauseVPKey, comboPauseVPKey.Text);
            writeSetting(iniPauseFPKey, comboPauseFPKey.Text);
            writeSettingBool(iniUseExitScreen, checkUseExitScreen.Checked);
            writeSetting(iniExitEmulatorKey, comboExitEmulatorKey.Text);
            writeSetting(iniExitEmulatorKey2, comboExitEmulatorKey2.Text);
            writeSetting(iniExitEmulatorKey3, comboExitEmulatorKey3.Text);
            writeSettingBool(iniHideCursor, checkHideCursor.Checked);
            writeSettingBool(iniHideDesktop, checkHideDesktop.Checked);
            writeSettingBool(iniHideTaskbar, checkHideTaskbar.Checked);
            writeSetting(iniToggleCursorKey, comboToggleCursorKey.Text);
            writeSettingBool(iniSaveFPTables, checkSaveFPTables.Checked);
            writeSetting(iniExitScriptKey, textExitScriptKey.Text);
            writeSettingInt(iniFadeSpeed, (int)numericFadeSpeed.Value);
        }

        public void updateOptionalControls()
        {
            checkUseExitAsPause.Enabled = checkUsePauseKey.Checked;
            labelPauseVPKey.Enabled = checkUsePauseKey.Checked;
            comboPauseVPKey.Enabled = checkUsePauseKey.Checked;
            labelPauseFPKey.Enabled = checkUsePauseKey.Checked;
            comboPauseFPKey.Enabled = checkUsePauseKey.Checked;

            comboExitEmulatorKey.Enabled = checkUseExitScreen.Checked;
            comboExitEmulatorKey2.Enabled = checkUseExitScreen.Checked;
            comboExitEmulatorKey3.Enabled = checkUseExitScreen.Checked;

            labelToggleCursorKey.Enabled = checkHideCursor.Checked;
            comboToggleCursorKey.Enabled = checkHideCursor.Checked;
        }

        private void checkUsePauseKey_CheckedChanged(object sender, EventArgs e)
        {
            updateOptionalControls();
        }

        private void checkUseExitScreen_CheckedChanged(object sender, EventArgs e)
        {
            updateOptionalControls();
        }

        private void checkHideCursor_CheckedChanged(object sender, EventArgs e)
        {
            updateOptionalControls();
        }
    }
}
